var isInitialized = false;
var toolWindowID = undefined;
var rootPanel = undefined;
var rootPanelObj = undefined;
function setupToolWindow() {
  rootPanel = document.getElementById("toolWindowRootPanel");
  rootPanel.isVerticalPanel = true;
  rootPanel.isToolWindow = true;
  rootPanel.countOfSections = 0;
  rootPanel.addPanelSection = addVerticalPanelSection;
  rootPanel.layoutChanged = () => {};
  rootPanel.closeButtonClicked = () => {
    window.chrome.webview.postMessage("X");
  };
}
window.chrome.webview.addEventListener("message", (e) => {
  if (isInitialized) {
    if (e.data.type === "getNodesUISnapshotResponse") {
      rootPanelObj.tree.view.gotNodesUISnapshotResponse(
        e.data.requestID,
        e.data.data
      );
    } else if (e.data.type === "treeChanged") {
      rootPanelObj.tree.renderNow();
    } else {
      alert(JSON.stringify(e.data));
    }
  } else {
    isInitialized = true;
    toolWindowID = e.data.toolWindowID;
    document.getElementById("cssTheme").href =
      "styles-" + "twinbasic-" + e.data.colorTheme + ".css";
    if (e.data.msg === "PROBLEMS") {
      document.body.innerHTML = "<div id='toolWindowRootPanel'></div>";
      setupToolWindow();
      createProblemsPanel(rootPanel, true);
      rootPanelObj = problemsPanel;
      problemsPanel.tree.sectionHeaderInner.onmousedown = () => {
        window.chrome.webview.postMessage("D");
      };
    } else if (e.data.msg === "OUTLINE") {
      document.body.innerHTML = "<div id='toolWindowRootPanel'></div>";
      setupToolWindow();
      createOutlinePanel(rootPanel, true);
      rootPanelObj = outlinePanel;
      outlinePanel.tree.sectionHeaderInner.onmousedown = () => {
        window.chrome.webview.postMessage("D");
      };
    }
    window.chrome.webview.postMessage(
      JSON.stringify({ toolWindowID: toolWindowID })
    );
  }
});
const VIRTUALTREE_LISTOFFSET_CAPTION = 0;
const VIRTUALTREE_LISTOFFSET_NEXTNODE = 1;
const VIRTUALTREE_LISTOFFSET_PREVNODE = 2;
const VIRTUALTREE_LISTOFFSET_FIRSTCHILD = 3;
const VIRTUALTREE_LISTOFFSET_LASTCHILD = 4;
const VIRTUALTREE_LISTOFFSET_PARENTNODE = 5;
const VIRTUALTREE_LISTOFFSET_FLAGS = 6;
const VIRTUALTREE_LISTOFFSET_MAX = 7;
const VTREEFLAG_ISEXPANDED = 1;
const VTREEFLAG_GROUP1 = 2;
const VTREEFLAG_GROUP2 = 4;
class virtualTreeViewData {
  constructor(e, t) {
    this.controller = e;
    this.CountOfCustomProperties = t;
    this.CountOfFlatEntriesPerNode =
      VIRTUALTREE_LISTOFFSET_MAX + this.CountOfCustomProperties;
    this.isMultiUpdate = 0;
  }
  clear() {
    this.countOfVisibleNodes = 0;
    this.flatData = [];
    this.treeUniqueItemId = 1;
    this.countOfAllNodes = 0;
    this.deletedNodeIndexes = [];
    this.hideGroup1 = false;
    this.hideGroup2 = false;
    this.rootFolder = this.addSubNode();
    this.controller.onClearData();
  }
  setExpanded(e, t) {
    var i = this.flatData[e + VIRTUALTREE_LISTOFFSET_FLAGS];
    this.flatData[e + VIRTUALTREE_LISTOFFSET_FLAGS] =
      (i & ~VTREEFLAG_ISEXPANDED) | (t ? VTREEFLAG_ISEXPANDED : 0);
  }
  isExpanded(e) {
    var t = this.flatData[e + VIRTUALTREE_LISTOFFSET_FLAGS];
    return t & VTREEFLAG_ISEXPANDED;
  }
  setCustomData(e, t, i) {
    if (t <= this.CountOfCustomProperties) {
      this.flatData[e + VIRTUALTREE_LISTOFFSET_MAX + t] = i;
    } else {
      debugger;
    }
  }
  addSubNode(e, t, i, n, a, o, s, r) {
    var l;
    if (this.deletedNodeIndexes.length > 0) {
      l = this.deletedNodeIndexes.pop();
    } else {
      this.countOfAllNodes++;
      l = this.treeUniqueItemId;
      this.treeUniqueItemId +=
        VIRTUALTREE_LISTOFFSET_MAX + this.CountOfCustomProperties;
      this.flatData.length +=
        VIRTUALTREE_LISTOFFSET_MAX + this.CountOfCustomProperties;
    }
    if (i !== undefined && 1 <= this.CountOfCustomProperties) {
      this.flatData[l + VIRTUALTREE_LISTOFFSET_MAX] = i;
    }
    if (n !== undefined && 2 <= this.CountOfCustomProperties) {
      this.flatData[l + VIRTUALTREE_LISTOFFSET_MAX + 1] = n;
    }
    if (a !== undefined && 3 <= this.CountOfCustomProperties) {
      this.flatData[l + VIRTUALTREE_LISTOFFSET_MAX + 2] = a;
    }
    if (o !== undefined && 4 <= this.CountOfCustomProperties) {
      this.flatData[l + VIRTUALTREE_LISTOFFSET_MAX + 3] = o;
    }
    this.flatData[l + VIRTUALTREE_LISTOFFSET_FLAGS] =
      (s ? VTREEFLAG_GROUP1 : 0) ||
      (r ? VTREEFLAG_GROUP2 : 0) ||
      VTREEFLAG_ISEXPANDED;
    if (e) {
      this.flatData[l + VIRTUALTREE_LISTOFFSET_PARENTNODE] = e;
      this.flatData[l + VIRTUALTREE_LISTOFFSET_CAPTION] = t;
      var d = this.flatData[e + VIRTUALTREE_LISTOFFSET_LASTCHILD];
      if (d) {
        this.flatData[d + VIRTUALTREE_LISTOFFSET_NEXTNODE] = l;
        this.flatData[l + VIRTUALTREE_LISTOFFSET_PREVNODE] = d;
      } else {
        this.flatData[e + VIRTUALTREE_LISTOFFSET_FIRSTCHILD] = l;
      }
      this.flatData[e + VIRTUALTREE_LISTOFFSET_LASTCHILD] = l;
    }
    return l;
  }
  getNextVisibleNode2(e, t, i) {
    while (1) {
      e = this.getNextVisibleNode(e, t, i);
      if (e === undefined) return undefined;
      if (
        (this.hideGroup1 &&
          this.flatData[e + VIRTUALTREE_LISTOFFSET_FLAGS] & VTREEFLAG_GROUP1) ||
        (this.hideGroup2 &&
          this.flatData[e + VIRTUALTREE_LISTOFFSET_FLAGS] & VTREEFLAG_GROUP2)
      ) {
      } else {
        break;
      }
    }
    return e;
  }
  getNextVisibleNode(e, t, i) {
    if (!t) {
      if (
        i ||
        this.flatData[e + VIRTUALTREE_LISTOFFSET_FLAGS] & VTREEFLAG_ISEXPANDED
      ) {
        var n = this.flatData[e + VIRTUALTREE_LISTOFFSET_FIRSTCHILD];
        if (n) {
          return n;
        }
      }
    }
    var a = this.flatData[e + VIRTUALTREE_LISTOFFSET_NEXTNODE];
    if (a) {
      return a;
    }
    var o = this.flatData[e + VIRTUALTREE_LISTOFFSET_PARENTNODE];
    if (o) {
      if (o !== 1) {
        return this.getNextVisibleNode(o, true);
      }
    }
    return undefined;
  }
  deleteNode(e) {
    this.deleteNodeChildren(e);
    var t = this.flatData[e + VIRTUALTREE_LISTOFFSET_NEXTNODE];
    var i = this.flatData[e + VIRTUALTREE_LISTOFFSET_PREVNODE];
    if (t) {
      this.flatData[t + VIRTUALTREE_LISTOFFSET_PREVNODE] = i;
    }
    if (i) {
      this.flatData[i + VIRTUALTREE_LISTOFFSET_NEXTNODE] = t;
    }
    var n = this.flatData[e + VIRTUALTREE_LISTOFFSET_PARENTNODE];
    if (n) {
      var a = this.flatData[n + VIRTUALTREE_LISTOFFSET_FIRSTCHILD];
      var o = this.flatData[n + VIRTUALTREE_LISTOFFSET_LASTCHILD];
      if (a == e) {
        this.flatData[n + VIRTUALTREE_LISTOFFSET_FIRSTCHILD] = t;
      }
      if (o == e) {
        this.flatData[n + VIRTUALTREE_LISTOFFSET_LASTCHILD] = i;
      }
    }
    var s = e;
    var r = s + VIRTUALTREE_LISTOFFSET_MAX + this.CountOfCustomProperties;
    while (s < r) {
      this.flatData[s++] = 0;
    }
    this.deletedNodeIndexes.push(e);
  }
  deleteNodeChildren(e) {
    var t = this.flatData[e + VIRTUALTREE_LISTOFFSET_FIRSTCHILD];
    while (t) {
      var i = this.flatData[t + VIRTUALTREE_LISTOFFSET_NEXTNODE];
      this.deleteNode(t);
      t = i;
    }
  }
  updateVisibleNodesList() {
    if (this.isMultiUpdate) return;
    this.visibleNodesList = new Array(this.countOfAllNodes);
    var e = 0;
    var t = 1;
    while (t) {
      if (t !== 1) {
        this.visibleNodesList[e++] = t;
      }
      t = this.getNextVisibleNode2(t);
    }
    this.countOfVisibleNodes = e;
    this.controller.renderNow();
    if (this.controller.associatedToolWindows) {
      this.controller.associatedToolWindows.forEach((e) => {
        e.postMessageObject({ type: "treeChanged" });
      });
    }
  }
  startMultiUpdate() {
    this.isMultiUpdate++;
  }
  endMultiUpdate() {
    this.isMultiUpdate--;
    if (this.isMultiUpdate == 0) {
      this.updateVisibleNodesList();
    }
  }
  endMultiUpdateNoChanges() {
    this.isMultiUpdate--;
  }
  generateNodeInfo(e) {
    var t = this;
    return {
      getNodeIndex() {
        return e;
      },
      isExpanded() {
        return t.isExpanded(e);
      },
      getCaption() {
        return t.flatData[e + VIRTUALTREE_LISTOFFSET_CAPTION];
      },
      getCustomData(i) {
        return t.flatData[e + VIRTUALTREE_LISTOFFSET_MAX + i];
      },
      getParentNodeInfo() {
        var i = t.flatData[e + VIRTUALTREE_LISTOFFSET_PARENTNODE];
        return t.generateNodeInfo(i);
      },
      hasChildren() {
        var i = t.flatData[e + VIRTUALTREE_LISTOFFSET_FIRSTCHILD];
        return i !== undefined;
      },
      expand() {
        var i = t.flatData[e + VIRTUALTREE_LISTOFFSET_FLAGS];
        if ((i & VTREEFLAG_ISEXPANDED) == 0) {
          t.flatData[e + VIRTUALTREE_LISTOFFSET_FLAGS] =
            i ^ VTREEFLAG_ISEXPANDED;
        }
        t.updateVisibleNodesList();
      },
      collapse() {
        var i = t.flatData[e + VIRTUALTREE_LISTOFFSET_FLAGS];
        if (i & VTREEFLAG_ISEXPANDED) {
          t.flatData[e + VIRTUALTREE_LISTOFFSET_FLAGS] =
            i ^ VTREEFLAG_ISEXPANDED;
        }
        t.updateVisibleNodesList();
      },
    };
  }
  getHTMLNode(e) {
    let t = this.visibleNodesList[e];
    let i = this.generateNodeInfo(t);
    return this.controller.renderDomNode(i);
  }
  onClickNode(e) {
    let t = this.visibleNodesList[e];
    let i = this.generateNodeInfo(t);
    this.controller.onClickNode(i);
  }
  onRightClickNode(e, t, i) {
    let n = this.visibleNodesList[e];
    let a = this.generateNodeInfo(n);
    this.controller.onRightClickNode(a, t, i);
  }
  onDblClickNode(e) {
    let t = this.visibleNodesList[e];
    let i = this.generateNodeInfo(t);
    this.controller.onDblClickNode(i);
  }
  toggleExpanded(e) {
    let t = this.visibleNodesList[e];
    var i = this.flatData[t + VIRTUALTREE_LISTOFFSET_FLAGS];
    this.flatData[t + VIRTUALTREE_LISTOFFSET_FLAGS] = i ^ VTREEFLAG_ISEXPANDED;
    this.updateVisibleNodesList();
  }
}
class virtualTreeViewView {
  constructor(e, t) {
    this.data = new virtualTreeViewData(e, t);
  }
  increaseCache() {}
  updateLocalCache(e) {
    e();
  }
  getCountOfVisibleNodes() {
    return this.data.countOfVisibleNodes;
  }
  getHTMLNode(e) {
    return this.data.getHTMLNode(e);
  }
  onClickNode(e) {
    return this.data.onClickNode(e);
  }
  onRightClickNode(e, t, i) {
    return this.data.onRightClickNode(e, t, i);
  }
  onDblClickNode(e) {
    return this.data.onDblClickNode(e);
  }
  toggleExpanded(e) {
    this.data.toggleExpanded(e);
  }
}
var g_UpdateLocalCacheCallback = undefined;
var g_UpdateLocalCacheRequestId = 0;
class virtualTreeViewAdditionalView {
  constructor(e) {
    this.controller = e;
    this.cachedLocalNodesCount = 10;
  }
  increaseCache() {
    this.cachedLocalNodesCount += 10;
  }
  updateLocalCache(e) {
    g_UpdateLocalCacheCallback = e;
    g_UpdateLocalCacheRequestId++;
    window.chrome.webview.postMessage(
      JSON.stringify({
        toolWindowID: toolWindowID,
        type: "getNodesUISnapshot",
        visibleIndex: this.controller.visibleTopNodeIndex,
        requestCount: this.cachedLocalNodesCount,
        requestID: g_UpdateLocalCacheRequestId,
      })
    );
  }
  gotNodesUISnapshotResponse(e, t) {
    if (e === g_UpdateLocalCacheRequestId) {
      this.cachedResponse = t;
      if (g_UpdateLocalCacheCallback) {
        var i = g_UpdateLocalCacheCallback;
        g_UpdateLocalCacheCallback = undefined;
        i();
      }
    }
  }
  getCountOfVisibleNodes() {
    return this.cachedResponse.totalVisibleNodesCount;
  }
  getHTMLNode(e) {
    if (
      e >=
      this.cachedResponse.visibleIndexStart +
        this.cachedResponse.htmlNodes.length
    ) {
      return undefined;
    }
    return this.cachedResponse.htmlNodes[
      e - this.cachedResponse.visibleIndexStart
    ];
  }
  onClickNode(e) {
    window.chrome.webview.postMessage(
      JSON.stringify({
        toolWindowID: toolWindowID,
        type: "clickedNode",
        visibleIndex: e,
      })
    );
  }
  onRightClickNode(e, t, i) {
    window.chrome.webview.postMessage(
      JSON.stringify({
        toolWindowID: toolWindowID,
        type: "rightClickedNode",
        visibleIndex: e,
        clientX: t,
        clientY: i,
      })
    );
  }
  onDblClickNode(e) {
    window.chrome.webview.postMessage(
      JSON.stringify({
        toolWindowID: toolWindowID,
        type: "dblClickedNode",
        visibleIndex: e,
      })
    );
  }
  toggleExpanded(e) {
    window.chrome.webview.postMessage(
      JSON.stringify({
        toolWindowID: toolWindowID,
        type: "toggleExpanded",
        visibleIndex: e,
      })
    );
  }
}
class virtualTreeView {
  constructor(e, t, i, n, a, o, s) {
    if (s) {
      this.view = new virtualTreeViewAdditionalView(this);
    } else {
      this.associatedToolWindows = [];
      this.view = new virtualTreeViewView(this, a);
      this.view.data.clear();
    }
    this.panelDiv = e;
    this.rootSelector = document.querySelector(":root");
    this.name = i;
    this.allowMultiSelect = n;
    this.friendlyName = t;
    this.cssVarsPrefix = o;
    this.cached_CountOfVisibleNodes = 0;
    this.visibleTopNodeIndex = 0;
  }
  getNodesUISnapshot(e, t) {
    var i = {
      htmlNodes: [],
      totalVisibleNodesCount: this.view.data.countOfVisibleNodes,
      visibleIndexStart: 0,
    };
    var n = e;
    if (
      n >= this.view.data.countOfVisibleNodes &&
      this.view.data.countOfVisibleNodes > 0
    ) {
      n = this.view.data.countOfVisibleNodes - 1;
    }
    if (n + t > this.view.data.countOfVisibleNodes) {
      t = this.view.data.countOfVisibleNodes - n;
    }
    if (t < 0) t = 0;
    var a = 0;
    while (a < t) {
      i.htmlNodes[a] = this.view.getHTMLNode(n + a);
      a++;
    }
    i.visibleIndexStart = n;
    return i;
  }
  onClearData() {
    if (this.sectionRoot) this.view.data.updateVisibleNodesList();
  }
  scrollY(e) {
    e /= 100;
    if (e > 0) {
      while (e > 0) {
        var t = this.visibleTopNodeIndex + 1;
        if (t >= this.cached_CountOfVisibleNodes) break;
        this.visibleTopNodeIndex = t;
        e -= 1;
      }
    } else {
      while (e < 0) {
        var i = this.visibleTopNodeIndex - 1;
        if (i < 0) break;
        this.visibleTopNodeIndex = i;
        e += 1;
      }
    }
    this.renderNow();
  }
  scrollToPosition(e) {
    var t = e / this.scrollBarVContainer.offsetHeight;
    var i = Math.trunc(this.cached_CountOfVisibleNodes * t);
    if (i < 0) i = 0;
    if (i > this.countOfVisibleNodes - 1) i = this.countOfVisibleNodes - 1;
    this.visibleTopNodeIndex = i;
    this.renderNow();
  }
  panelResized() {
    this.renderNow();
  }
  finishedInit() {
    if (this.panelDiv.isToolWindow) {
      var e = createDOMElement(
        this.sectionHeader,
        "div",
        "panelHeaderIcon closeIcon"
      );
      e.onclick = (e) => {
        this.panelDiv.closeButtonClicked();
      };
    }
  }
  init() {
    this.sectionExpander = createDOMElement(
      undefined,
      "div",
      "panelHeaderIconLeft sectionExpanderIcon"
    );
    this.sectionHeaderInner = createDOMElement(
      undefined,
      "div",
      "sectionHeaderInner",
      this.friendlyName
    );
    this.filterTextOuter = createDOMElement(
      undefined,
      "div",
      "filterTextOuter"
    );
    this.filterText = createDOMElement(
      this.filterTextOuter,
      "div",
      "filterText"
    );
    this.sectionRoot = createDOMElement(
      undefined,
      "div",
      "sectionRootNoScroll"
    );
    this.sectionBody = createDOMElement(this.sectionRoot, "div", "sectionBody");
    this.scrollBarVContainer = createDOMElement(
      this.sectionRoot,
      "div",
      "scrollBarVContainer" + this.friendlyName
    );
    this.scrollBarV = createDOMElement(
      this.scrollBarVContainer,
      "div",
      "scrollBarV" + this.friendlyName
    );
    this.treeDiv = createDOMElement(
      this.sectionBody,
      "div",
      "tree treeCustomScroll"
    );
    new ResizeObserver(() => this.panelResized()).observe(this.sectionRoot);
    this.scrollBarVContainer.addEventListener(
      "mousedown",
      (e) => {
        this.scrollToPosition(e.layerY - this.scrollBarVContainer.offsetTop);
      },
      false
    );
    this.scrollBarV.addEventListener(
      "mousedown",
      (e) => {
        this.mouseDownListener = (e) => {
          var { top: t } = this.scrollBarVContainer.getBoundingClientRect();
          this.scrollToPosition(e.pageY - t);
          e.stopPropagation();
        };
        this.mouseUpListener = () => {
          document.removeEventListener("mousemove", this.mouseDownListener);
          document.removeEventListener("mouseup", this.mouseUpListener);
        };
        document.addEventListener("mousemove", this.mouseDownListener, false);
        document.addEventListener("mouseup", this.mouseUpListener, false);
        e.stopPropagation();
      },
      false
    );
    this.sectionRoot.addEventListener(
      "wheel",
      (e) => {
        this.scrollY(e.deltaY);
        e.preventDefault();
      },
      false
    );
    assignToPanel(this, undefined, this.panelDiv);
    this.allocatedDomNodes = createDOMElement(this.treeDiv, "div");
  }
  renderNow() {
    this.view.updateLocalCache(() => {
      var e = this.allocatedDomNodes;
      const t = this.sectionRoot.getBoundingClientRect();
      if (t.bottom === 0) {
        setTimeout(() => this.renderNow(), 1e3);
        return;
      }
      var i = this.visibleTopNodeIndex;
      var n = this.view.getCountOfVisibleNodes();
      this.cached_CountOfVisibleNodes = n;
      if (i >= n && n > 0) {
        i = n - 1;
      }
      this.rootSelector.style.setProperty(
        this.cssVarsPrefix + "ScrollPosition",
        i
      );
      this.rootSelector.style.setProperty(this.cssVarsPrefix + "ScrollMax", n);
      this.rootSelector.style.setProperty(
        this.cssVarsPrefix + "ScrollOpacity",
        1
      );
      var a = false;
      while (i < n) {
        var o = this.view.getHTMLNode(i);
        if (o === undefined) {
          this.view.increaseCache();
          this.renderNow();
          return;
        }
        e.innerHTML = o;
        const { bottom: n } = e.getBoundingClientRect();
        if (!e.nextDomNode) {
          e.nextDomNode = createDOMElement(this.treeDiv, "div");
          let t = e;
          e.onclick = (e) => {
            this.view.onClickNode(t.nodeVisibleIndex);
          };
          e.oncontextmenu = (e) => {
            this.view.onRightClickNode(
              t.nodeVisibleIndex,
              e.clientX,
              e.clientY
            );
          };
          e.ondblclick = (e) => {
            this.view.onDblClickNode(t.nodeVisibleIndex);
          };
        }
        e.nodeVisibleIndex = i++;
        e = e.nextDomNode;
        if (n > t.bottom) {
          a = true;
          break;
        }
      }
      if (!a) {
        if (this.visibleTopNodeIndex === 0) {
          this.rootSelector.style.setProperty(
            this.cssVarsPrefix + "ScrollOpacity",
            0
          );
        }
      }
      while (e) {
        e.innerHTML = "";
        e = e.nextDomNode;
      }
    });
  }
}
var outlinePanelOptions = {
  showClassFields: true,
  showModuleVariables: true,
  showEnumerations: true,
  showUDTs: true,
  showDLLs: true,
  showConstructors: true,
  showProperties: true,
  showProcedures: true,
  showVariables: true,
  showParameters: true,
};
function toggleOutlineShow(e) {
  outlinePanelOptions[e.id] = outlinePanelOptions[e.id] ? false : true;
  if (outlinePanelOptions[e.id]) {
    e.iconClassDiv.classList.add("tickIcon");
    e.iconClassDiv.classList.remove("noTickIcon");
  } else {
    e.iconClassDiv.classList.remove("tickIcon");
    e.iconClassDiv.classList.add("noTickIcon");
  }
  outlinePanel.rebuildFilteredTypes();
  outlinePanel.resync();
  return true;
}
function toggleOutlineGetIconClass(e) {
  return outlinePanelOptions[e] ? "tickIcon" : "noTickIcon";
}
function initOutlinesPanel() {}
var outlinePanel = undefined;
const OUTLINEPANEL_CUSTOMPROPERTY_DETAIL = 0;
const OUTLINEPANEL_CUSTOMPROPERTY_LINENUM = 1;
const OUTLINEPANEL_CUSTOMPROPERTY_CHARNUM = 2;
const OUTLINEPANEL_CUSTOMPROPERTY_INDENTLEVEL = 3;
const _OUTLINEPANEL_CUSTOMPROPERTY_MAXCOUNT = 4;
class _outlinePanel {
  constructor(e, t) {
    var i = _OUTLINEPANEL_CUSTOMPROPERTY_MAXCOUNT;
    this.id = 0;
    this.tree = new virtualTreeView(
      e,
      "OUTLINE",
      "twinbasic-outline:",
      false,
      i,
      "--outline",
      t
    );
    this.tree.showFolderIcons = false;
    this.tree.autoExpandOnSelect = false;
    this.tree.showTooltips = true;
    this.tree.additionalFolderClassNames = "testTree";
    this.tree.emptyFolderText = "";
    this.tree.renderDomNode = (e) => {
      var t = e.getCustomData(OUTLINEPANEL_CUSTOMPROPERTY_DETAIL);
      var i = e.getCustomData(OUTLINEPANEL_CUSTOMPROPERTY_INDENTLEVEL);
      var n = e.hasChildren();
      let a = "";
      if (n) {
        if (e.isExpanded()) {
          a =
            "<div class='outlineNodeGroupIcon iconCollapse14' onclick='toggleOutlineNode(event)'></div>";
        } else {
          a =
            "<div class='outlineNodeGroupIcon iconExpand14' onclick='toggleOutlineNode(event)'></div>";
        }
      }
      return (
        "<div class='outlineNodeItem' style='padding-left:" +
        i * 15 +
        "px'>" +
        a +
        e.getCaption() +
        (t ? "<div class='outlineNodeDetail'>" + t + "</div>" : "") +
        "</div>"
      );
    };
    this.tree.onClickNode = (e) => {
      var t = e.getCustomData(OUTLINEPANEL_CUSTOMPROPERTY_LINENUM);
      var i = e.getCustomData(OUTLINEPANEL_CUSTOMPROPERTY_CHARNUM);
      revealLineInEditor(t + 1, i + 1);
    };
    this.tree.init();
    if (!e.isToolWindow) {
      var n = createDOMElement(
        this.tree.sectionHeader,
        "div",
        "panelHeaderIcon ellipsesIcon"
      );
      n.onclick = (e) => {
        showContextMenu(undefined, e.clientX, e.clientY, [
          {
            id: "sortAlphabetically",
            name: "Sort Alphabetically",
            action: (e) => toggleOutlineShow(e),
            iconClass: toggleOutlineGetIconClass("sortAlphabetically"),
          },
          {},
          {
            id: "showClassFields",
            name: "Show Class Fields",
            action: (e) => toggleOutlineShow(e),
            iconClass: toggleOutlineGetIconClass("showClassFields"),
          },
          {
            id: "showModuleVariables",
            name: "Show Module Variables",
            action: (e) => toggleOutlineShow(e),
            iconClass: toggleOutlineGetIconClass("showModuleVariables"),
          },
          {
            id: "showEnumerations",
            name: "Show Enumerations",
            action: (e) => toggleOutlineShow(e),
            iconClass: toggleOutlineGetIconClass("showEnumerations"),
          },
          {
            id: "showUDTs",
            name: "Show User Defined Types",
            action: (e) => toggleOutlineShow(e),
            iconClass: toggleOutlineGetIconClass("showUDTs"),
          },
          {
            id: "showDLLs",
            name: "Show DLL Declares",
            action: (e) => toggleOutlineShow(e),
            iconClass: toggleOutlineGetIconClass("showDLLs"),
          },
          {
            id: "showConstructors",
            name: "Show Constructors",
            action: (e) => toggleOutlineShow(e),
            iconClass: toggleOutlineGetIconClass("showConstructors"),
          },
          {
            id: "showProperties",
            name: "Show Properties (Get/Let/Set)",
            action: (e) => toggleOutlineShow(e),
            iconClass: toggleOutlineGetIconClass("showProperties"),
          },
          {
            id: "showProcedures",
            name: "Show Procedures",
            action: (e) => toggleOutlineShow(e),
            iconClass: toggleOutlineGetIconClass("showProcedures"),
          },
          {
            id: "showVariables",
            name: "Show Variables",
            action: (e) => toggleOutlineShow(e),
            iconClass: toggleOutlineGetIconClass("showVariables"),
          },
          {
            id: "showParameters",
            name: "Show Parameters",
            action: (e) => toggleOutlineShow(e),
            iconClass: toggleOutlineGetIconClass("showParameters"),
          },
        ]);
        e.stopPropagation();
      };
    }
    this.tree.finishedInit();
  }
  rebuildFilteredTypes() {
    this.filteredTypes = {};
    if (!outlinePanelOptions["showClassFields"]) {
      this.filteredTypes["5_8"] = true;
    }
    if (!outlinePanelOptions["showModuleVariables"]) {
      this.filteredTypes["2_8"] = true;
    }
    if (!outlinePanelOptions["showEnumerations"]) {
      this.filteredTypes["5_10"] = true;
      this.filteredTypes["2_10"] = true;
    }
    if (!outlinePanelOptions["showUDTs"]) {
      this.filteredTypes["5_23"] = true;
      this.filteredTypes["2_23"] = true;
    }
    if (!outlinePanelOptions["showDLLs"]) {
      this.filteredTypes["5_524"] = true;
      this.filteredTypes["2_524"] = true;
    }
    if (!outlinePanelOptions["showConstructors"]) {
      this.filteredTypes["5_9"] = true;
    }
    if (!outlinePanelOptions["showProperties"]) {
      this.filteredTypes["5_7"] = true;
      this.filteredTypes["2_7"] = true;
    }
    if (!outlinePanelOptions["showProcedures"]) {
      this.filteredTypes["5_12"] = true;
      this.filteredTypes["2_12"] = true;
    }
    if (!outlinePanelOptions["showVariables"]) {
      this.filteredTypes["5_12_8"] = true;
      this.filteredTypes["5_7_8"] = true;
      this.filteredTypes["5_9_8"] = true;
      this.filteredTypes["2_12_8"] = true;
      this.filteredTypes["2_7_8"] = true;
    }
    if (!outlinePanelOptions["showParameters"]) {
      this.filteredTypes["5_524_520"] = true;
      this.filteredTypes["5_12_520"] = true;
      this.filteredTypes["5_7_520"] = true;
      this.filteredTypes["5_9_520"] = true;
      this.filteredTypes["2_524_520"] = true;
      this.filteredTypes["2_12_520"] = true;
      this.filteredTypes["2_7_520"] = true;
    }
  }
  syncSymbolsToFolder(e, t, i, n) {
    var a = e;
    if (this.sort) {
      a = e.slice();
      a.sort((e, t) => e.name.localeCompare(t.name));
    }
    if (this.filteredTypes === undefined) {
      this.rebuildFilteredTypes();
    }
    a.forEach((e) => {
      if (!this.filteredTypes[i + e.kind]) {
        if (e.children && e.children.length > 0) {
          var a = this.tree.view.data.addSubNode(
            t,
            e.name,
            e.detail,
            e.range.start.line,
            e.range.start.character,
            n
          );
          this.syncSymbolsToFolder(e.children, a, i + e.kind + "_", n + 1);
        } else {
          var o = this.tree.view.data.addSubNode(
            t,
            e.name,
            e.detail,
            e.range.start.line,
            e.range.start.character,
            n
          );
        }
      }
    });
  }
  syncSymbols(e) {
    this.tree.view.data.startMultiUpdate();
    this.tree.view.data.clear();
    this.sort = outlinePanelOptions["sortAlphabetically"] ? true : false;
    this.cachedSymbols = e;
    this.syncSymbolsToFolder(e, this.tree.view.data.rootFolder, "", 0);
    this.tree.view.data.endMultiUpdate();
  }
  resync() {
    this.syncSymbols(this.cachedSymbols);
  }
}
function toggleOutlineNode(e) {
  outlinePanel.tree.view.toggleExpanded(
    e.target.parentNode.parentNode.nodeVisibleIndex
  );
  e.stopPropagation();
}
function createOutlinePanel(e, t) {
  if (outlinePanel) return outlinePanel;
  outlinePanel = new _outlinePanel(e, t);
}
var packageManagerPanel = undefined;
var packageManagerPublisher = undefined;
var packageManagerNamespace = undefined;
var packageManagerDescription = undefined;
var packageManagerLicence = undefined;
var packageManagerVisibility = undefined;
var packageManagerVersion = undefined;
var packagePublisherName = "";
var packagePublisherPassword = "";
var packagePublisherSessionID = "";
var packagePublisherRememberPassword = false;
var packageManagerPublisherSingInLinkDomElement = undefined;
function ObfuscateString(e, t, i = 126) {
  var n = e.toString().split("");
  for (var a = 0; a < n.length; a++) {
    var o = n[a].charCodeAt(0);
    if (o <= i) {
      n[a] = String.fromCharCode((n[a].charCodeAt(0) + t) % i);
    }
  }
  return n.join("");
}
function UnobfuscateString(e, t, i = 126) {
  return ObfuscateString(e, i - t);
}
async function loadPublisherInfo() {
  await hostAppObject.GetIDESetting("PUBLISHER");
  var e = await hostAppObject.GetIDESetting("PUBLISHER");
  if (e) {
    var t = parseJson(e);
    if (t) {
      packagePublisherName = t.name ? t.name : "";
      packagePublisherPassword = t.pass ? UnobfuscateString(t.pass, 111) : "";
      if (packagePublisherPassword.length > 0)
        packagePublisherRememberPassword = true;
    }
  }
}
async function savePublisherInfo() {
  var e = { name: packagePublisherName };
  if (packagePublisherRememberPassword)
    e.pass = ObfuscateString(packagePublisherPassword, 111);
  await hostAppObject.SaveIDESetting("PUBLISHER", JSON.stringify(e));
}
function addCssClass(e) {
  document.getElementsByClassName("simpleMsgBoxNoImage")[0].classList.add(e);
}
function removeCssClass(e) {
  document.getElementsByClassName("simpleMsgBoxNoImage")[0].classList.remove(e);
}
function focusElement(e) {
  document.getElementById(e).focus();
}
function simulateClick(e) {
  document.getElementById(e).click();
}
function setPublisherError(e) {
  var t = document.getElementById("PublisherError");
  if (t) t.innerText = e.length > 0 ? "ERROR: " + e : "";
}
function serverHttpsGetUtf8(e, t, i, n, a) {
  e = e.replaceAll("#", "%23");
  var o = new XMLHttpRequest();
  o.onreadystatechange = () => {
    if (o.readyState == 4 && o.status == 200) {
      if (t) t(o.responseText);
    } else if (o.readyState == 4 && o.status != 0) {
      if (i) i(o.status);
    }
  };
  o.onerror = () => {
    if (i) i(o.status);
  };
  o.overrideMimeType("text/plain; charset=UTF-8");
  o.open(n ? "POST" : "GET", "https://www.everythingaccess.com" + e, true);
  if (a) {
    a.forEach((e) => {
      o.setRequestHeader(e.name, e.value);
    });
  }
  o.send(n ? n : null);
}
function getInputValue(e) {
  var t = document.getElementById(e);
  if (t.type === "checkbox") {
    return t.checked;
  }
  return t.value;
}
function packagePublisherPublishNow(e, t, i) {
  debugOutputLine(
    "[PUBLISH] attempting to publish project '" +
      t +
      "' to the online database..."
  );
  serverHttpsGetUtf8(
    "/twinbasic/packages/publish?auth=" + packagePublisherSessionID,
    () => {
      showModalNotification(
        "[PUBLISH] successful.  Your package should appear in the package manager database shortly."
      );
    },
    (e) => {
      debugger;
      if (!i && e == 552) {
        packageManagerPanel.showSignInForm();
      } else if (e == 551) {
        showModalNotification(
          "[PUBLISH] FAILED.  Package already uploaded with this exact version number."
        );
      } else if (e == 553) {
        showModalNotification(
          "[PUBLISH] FAILED.  Package already registered to another publisher (change your Project ID setting)."
        );
      } else if (e !== 200) {
        showModalNotification(
          "[PUBLISH] FAILED.  Server returned HTTPS code " + e,
          true
        );
      }
    },
    e,
    [
      { name: "Content-Type", value: "application/octet-stream" },
      { name: "Content-Length", value: e.length },
    ]
  );
}
function packagePublisherPublish() {
  if (packagePublisherSessionID.length == 0) {
    packageManagerPanel.showSignInForm();
    return;
  }
  debugSocket.request("generateTWINPACK", undefined, (e) => {
    var t = e.body;
    if (t.projectId == "{00000000-0000-0000-0000-000000000000}") {
      showModalNotification(
        `ERROR: Please first edit the Settings, giving the project a proper name and description`
      );
    } else {
      var i =
        root.RootProjectPackageVisibility === "PUBLIC"
          ? "WARNING: publishing a PUBLIC package will allow everyone to download the package and see the sourcecode within it.\r\n\r\n"
          : "";
      var n = `${i}IMPORTANT: Please check the following information before publishing to the online database:\r\n\r\nPUBLISHER: ${packagePublisherName}\r\n\r\nPACKAGE NAMESPACE: ${t.projectName}\r\nPACKAGE DESCRIPTION: ${t.projectDescription}\r\nPACKAGE VERSION: ${t.versionMajor}.${t.versionMinor}.${t.versionBuild}.${t.versionRevision}\r\n\r\nPACKAGE LICENCE: ${t.licence}\r\n\r\nDo you want to proceed?`;
      var a = createDOMElement(undefined, "div", "simpleMsgBox", n);
      showModalDialog(a, [
        {
          caption: "PROCEED",
          onclick: () => {
            hideModalDialog();
            base64ToBufferAsync(t.fileBase64, (e) => {
              packagePublisherPublishNow(e, t.projectName);
            });
          },
          isDefaultCancelAction: false,
        },
        {
          caption: "CANCEL",
          onclick: () => {
            hideModalDialog();
          },
          isDefaultCancelAction: true,
        },
      ]);
    }
  });
}
function packagePublisherRegister(e, t, i, n, a) {
  setPublisherError("");
  if (!e || e.length < 4) {
    setPublisherError("Username must be at least 4 characters long");
    focusElement("PublisherUserId");
    return;
  }
  const o = (e) =>
    String(e)
      .toLowerCase()
      .match(
        /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|.(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
      );
  if (!t || !o(t)) {
    setPublisherError("invalid email address");
    focusElement("PublisherEmail");
    return;
  }
  if (!i || i.length < 8) {
    setPublisherError("Password must be at least 8 characters long");
    focusElement("PublisherPassword");
    return;
  }
  if (n != true) {
    setPublisherError("You must agree to the terms and conditions");
    return;
  }
  packagePublisherRememberPassword = a == true;
  serverHttpsGetUtf8(
    "/twinbasic/packages/publisherCreate?id=" +
      e +
      "&email=" +
      t +
      "&password=" +
      i,
    (t) => {
      packagePublisherName = e;
      if (packagePublisherRememberPassword) packagePublisherPassword = i;
      packageManagerPanel.signOut();
      hideModalDialog();
      showModalNotification(
        "Publisher account created successfully.  You will now be logged in.",
        () => {
          savePublisherInfo();
          packagePublisherLogin(e, i, packagePublisherRememberPassword);
        }
      );
    },
    (e) => {
      if (e == 553) {
        setPublisherError("Username already taken.");
      } else if (e !== 0) {
        setPublisherError(
          "Publisher registration FAILED.  Server returned HTTPS code " + e
        );
      } else {
        setPublisherError(
          "Publisher registration FAILED.   HTTPS request to server (www.everythingaccess.com) failed.  Try again later."
        );
      }
    }
  );
}
function packagePublisherLogin(e, t, i) {
  packagePublisherName = e;
  packagePublisherPassword = t ? t : "";
  packageManagerPanel.packagePublisherLogin(() => {
    packagePublisherRememberPassword = i == true;
    packageManagerPublisher.innerText = packagePublisherName;
    savePublisherInfo();
    if (!i) packagePublisherPassword = "";
  });
}
function showPublisherSignInForm() {
  packageManagerPanel.showSignInForm();
}
function setPublisherSessionId(e) {
  packagePublisherSessionID = e ? e : "";
}
class _packageManagerPanel {
  show() {
    this._this.sectionRoot.classList.remove("sectionRootHidden");
    this._this.sectionHeader.classList.remove("sectionHeaderHidden");
  }
  hide() {
    this._this.sectionRoot.classList.add("sectionRootHidden");
    this._this.sectionHeader.classList.add("sectionHeaderHidden");
  }
  signOut() {
    packageManagerPublisher.innerText = "";
    packageManagerPublisherSingInLinkDomElement.innerText = "SIGN IN";
    setPublisherSessionId("");
  }
  packagePublisherLogin(e) {
    setPublisherError("");
    if (packagePublisherPassword.length == 0) {
      this.showSignInForm();
      return;
    }
    serverHttpsGetUtf8(
      "/twinbasic/packages/publisherLogin?id=" +
        packagePublisherName +
        "&password=" +
        packagePublisherPassword,
      (t) => {
        setPublisherSessionId(t);
        packageManagerPublisherSingInLinkDomElement.innerText = "SIGN OUT";
        hideModalDialog();
        if (e) e();
      },
      (e) => {
        if (e === 553) {
          setPublisherError(
            "Publisher login FAILED.  Username not found.",
            showPublisherSignInForm
          );
        } else if (e === 555) {
          setPublisherError(
            "Publisher login FAILED.  Incorrect password.",
            showPublisherSignInForm
          );
        } else if (e !== 0) {
          setPublisherError(
            "Publisher login FAILED.  Server returned HTTPS code " + e,
            showPublisherSignInForm
          );
        } else {
          setPublisherError(
            "Publisher login FAILED.  HTTPS request to server (www.everythingaccess.com) failed.  Try again later.",
            showPublisherSignInForm
          );
        }
      }
    );
  }
  showSignInForm(e) {
    var t = `\n                        <div id='PublisherSignUp'>\n                            <div id='LoginOptions'>\n                                <div id='LoginButton' onclick='addCssClass("isLogin"); focusElement("PublisherUserIdLogin");'>LOGIN</div>\n                                <div id='SignupButton' onclick='removeCssClass("isLogin"); focusElement("PublisherUserId");'>REGISTER</div>\n                            </div>\n\n                            <div id='PublisherLoginGroup'>\n                                <br/><div id='PublisherLogInUserIdLabel'>USERNAME</div><input id='PublisherUserIdLogin' type='text' value='${packagePublisherName}' onkeyup='if(event.keyCode == 13) focusElement("PublisherPasswordLogin"); return true;'/>\n                                <br/><div id='PublisherLogInPasswordLabel'>PASSWORD</div><input id='PublisherPasswordLogin' type='password' value='${packagePublisherPassword}' onkeyup='if(event.keyCode == 13) simulateClick("PublisherLogInButton"); return true;'/>\n                                <br/>\n                                <br/><div id='PublisherLoginRememberPasswordContainer'><input id='PublisherLoginRememberPassword' type='checkbox'/>Remember password on this device</div>    \n                                <br/><div id='PublisherLogInButton' onclick='packagePublisherLogin(getInputValue("PublisherUserIdLogin"), getInputValue("PublisherPasswordLogin"), getInputValue("PublisherLoginRememberPassword"));'>LOG IN &nbsp; &#10148;</div>    \n                            </div> \n                            <div id='PublisherSignupGroup'>\n                                <br/><div id='PublisherSignUpUserIdLabel'>USERNAME</div><div class='group'><input id='PublisherUserId' type='text' onkeydown='if(event.keyCode == 13) simulateClick("PublisherSignUpButton"); return true;'/><div class='keepTogether'>&gt;=4 characters, visible to everyone, no expletives</div></div>\n                                <br/><div id='PublisherSignUpEmailLabel'>EMAIL</div><div class='group'><input id='PublisherEmail' type='text' onkeydown='if(event.keyCode == 13) simulateClick("PublisherSignUpButton"); return true;'/><div class='keepTogether'>this is used for account recovery only</div></div>\n                                <br/><div id='PublisherSignUpPasswordLabel'>PASSWORD</div><div class='group'><input id='PublisherPassword' type='password' onkeydown='if(event.keyCode == 13) simulateClick("PublisherSignUpButton"); return true;'/><div class='keepTogether'>&gt;=8 characters</div></div>\n                                <br/><div id='PublisherAgreeTermsContainer'><input id='PublisherAgreeTerms' type='checkbox'/>I agree to the terms &amp; conditions</div>    \n                                <br/><div id='PublisherRememberPasswordContainer'><input id='PublisherRememberPassword' type='checkbox'/>Remember password on this device</div>    \n                                <br/><div id='PublisherSignUpButton' onclick='packagePublisherRegister(getInputValue("PublisherUserId"), getInputValue("PublisherEmail"), getInputValue("PublisherPassword"), getInputValue("PublisherAgreeTerms"), getInputValue("PublisherRememberPassword"));'>SIGN UP &nbsp; &#10148;</div>   \n                            </div> \n                            <div id='PublisherError'></div>    \n                        </div>\n\n                        <div id='terms'>\n                        <h2 style='margin-top: 0;'>TERMS AND CONDITIONS</h2>\n                        This service is subject to the following Terms and Conditions. &nbsp;These terms may be updated at any time without notice to you.\n                        <br/>\n                        <br/>This service allows you to store and share your content and/or receive material from others. &nbsp;We don't claim ownership of your content; it remains your content and you are responsible for it.\n                        <br/>\n                        <br/>Use of this service is at your own risk. &nbsp;Published packages may contain full source code which will be visible to everyone using this service.\n                        <ul>\n                            <li>Don't do anything illegal.</li>\n                            <li>Don't publish spam.</li>\n                            <li>Don't engage in any activity that exploits or harms children.</li>\n                            <li>Don't use the service to share inappropriate content (e.g., nudity, pornography, violence, or criminal activity).</li>\n                            <li>Don't attempt to circumvent security/authentication restrictions.</li>\n                            <li>Don't attempt to damage, overburden, or impair the services.</li>\n                            <li>Don't engage in any activity that is false or misleading (e.g., impersonating someone).</li>\n                            <li>Don't engage in any activity that is harmful to you, the service, or others (e.g., publishing viruses).</li>\n                            <li>Don't infringe upon the rights of others (e.g., unauthorized sharing of copyrighted material).</li>\n                            <li>Don't help others break these rules.</li>\n                        </ul>\n                        <br/>If you violate these terms, we may stop providing the service to you, close your account, revoke your access, or delete or unlist your package(s).\n                        <br/>\n                        <br/>In using the service, you agree to comply with all applicable Export Laws.\n                        <br/>\n                        <br/>If you have any basis for recovering damages, you agree that your exclusive remedy is to recover, from Wayne Phillips T/A iTech Masters or any affiliates, distributors, and vendors, direct aggregate damages up to £1.00. &nbsp;You can't recover any other damages or losses, including consequential, lost profits, special, indirect, incidental, or punitive. &nbsp;These limitations and exclusions apply even if this remedy doesn't fully compensate you for any losses or fails of its essential purpose or if we knew or should have known about the possibility of the damages. &nbsp;To the maximum extent permitted by law, these limitations and exclusions apply to all claims against the services provided, and the software related to the services.\n                        <br/>\n                        </div>\n                    `;
    var i = createDOMElement(undefined, "div", "simpleMsgBoxNoImage");
    i.innerHTML = t;
    showModalDialog(
      i,
      [
        {
          caption: "CANCEL",
          onclick: hideModalDialog,
          isDefaultCancelAction: true,
        },
      ],
      "twinBASIC Publisher Login / Signup"
    );
    if (packagePublisherName.length > 0) {
      addCssClass("isLogin");
      focusElement("PublisherPasswordLogin");
    } else {
      focusElement("PublisherUserId");
    }
    var n = document.getElementById("PublisherLoginRememberPassword");
    n.checked = packagePublisherRememberPassword;
  }
  constructor(e, t) {
    this.id = 0;
    var i = {};
    i.sectionExpander = createDOMElement(
      undefined,
      "div",
      "panelHeaderIconLeft sectionExpanderIcon"
    );
    i.panelDiv = e;
    i.sectionHeaderInner = createDOMElement(
      undefined,
      "div",
      "sectionHeaderInner",
      "PACKAGE PUBLISHING"
    );
    i.sectionRoot = createDOMElement(undefined, "div", "sectionRoot");
    i.sectionBody = createDOMElement(i.sectionRoot, "div", "sectionBody");
    var n = createDOMElement(i.sectionBody, "div", "packageManagerOuter");
    var a = createDOMElement(n, "div", "packageManagerInner");
    var o = createDOMElement(n, "div", "packageManagerInner2");
    {
      let e = createDOMElement(a, "div", "packageManagerRow");
      createDOMElement(e, "div", "packageManagerHeader", "Publisher");
      packageManagerPublisher = createDOMElement(
        e,
        "div",
        "packageManagerData"
      );
      let t = createDOMElement(e, "div", "packageManagerLink", "SIGN IN");
      t.onclick = () => {
        if (packagePublisherSessionID.length > 0) {
          this.signOut();
        } else {
          this.showSignInForm();
        }
      };
      packageManagerPublisherSingInLinkDomElement = t;
    }
    {
      let e = createDOMElement(a, "div", "packageManagerRow");
      createDOMElement(e, "div", "packageManagerHeader", "Namespace");
      packageManagerNamespace = createDOMElement(
        e,
        "div",
        "packageManagerData"
      );
      let t = createDOMElement(e, "div", "packageManagerLink", "EDIT");
      t.onclick = () => {
        showIndividualSetting("project.name");
      };
    }
    {
      let e = createDOMElement(a, "div", "packageManagerRow");
      createDOMElement(e, "div", "packageManagerHeader", "Description");
      packageManagerDescription = createDOMElement(
        e,
        "div",
        "packageManagerData"
      );
      let t = createDOMElement(e, "div", "packageManagerLink", "EDIT");
      t.onclick = () => {
        showIndividualSetting("project.description");
      };
    }
    {
      let e = createDOMElement(a, "div", "packageManagerRow");
      createDOMElement(e, "div", "packageManagerHeader", "Licence");
      packageManagerLicence = createDOMElement(e, "div", "packageManagerData");
      let t = createDOMElement(e, "div", "packageManagerLink", "EDIT");
      t.onclick = () => {
        showIndividualSetting("project.licence");
      };
    }
    {
      let e = createDOMElement(a, "div", "packageManagerRow");
      createDOMElement(e, "div", "packageManagerHeader", "Visibility");
      packageManagerVisibility = createDOMElement(
        e,
        "div",
        "packageManagerData"
      );
      let t = createDOMElement(e, "div", "packageManagerLink", "EDIT");
      t.onclick = () => {
        showIndividualSetting("project.packageVisibility");
      };
    }
    {
      let e = createDOMElement(a, "div", "packageManagerRow");
      createDOMElement(e, "div", "packageManagerHeader", "Version");
      packageManagerVersion = createDOMElement(e, "div", "packageManagerData");
      let t = createDOMElement(e, "div", "packageManagerLink", "EDIT");
      t.onclick = () => {
        showIndividualSetting("project.version");
      };
    }
    {
      let e = createDOMElement(o, "div", "packageManagerFullLine");
      e.innerText = "(changes not effective until published)";
    }
    {
      let e = createDOMElement(o, "div", "packageManagerPublish");
      e.innerText = "PUBLISH THIS PACKAGE";
      e.onclick = () => {
        packagePublisherPublish();
      };
    }
    a.spellcheck = false;
    a.autocomplete = false;
    i.friendlyName = "PACKAGE PUBLISHING";
    assignToPanel(i, undefined, i.panelDiv);
    i.sectionHeader.sectionRoot = i.sectionRoot;
    if (i.sectionHeader.restoreCustomSize) i.sectionHeader.restoreCustomSize();
    i.sectionHeader.panelId = "PACKAGE PUBLISHING";
    this._this = i;
    this.hide();
  }
}
function syncPackageManagerPanel() {
  packageManagerNamespace.innerText = g_CurrentProjectName;
  packageManagerDescription.innerText = g_CurrentProjectDescription;
  packageManagerLicence.innerText = g_CurrentProjectLicence;
  packageManagerVisibility.innerText = g_CurrentProjectVisibility;
  packageManagerVersion.innerText =
    g_CurrentProjectMajorVersion +
    "." +
    g_CurrentProjectMinorVersion +
    "." +
    g_CurrentProjectBuildVersion +
    "." +
    g_CurrentProjectRevisionVersion;
  if (g_CurrentProjectIsPackage) {
    packageManagerPanel.show();
  } else {
    packageManagerPanel.hide();
  }
}
function createPackageManagerPanel(e, t) {
  if (packageManagerPanel) return packageManagerPanel;
  packageManagerPanel = new _packageManagerPanel(e, t);
}
function initProblemsPanel() {}
var problemsPanel = undefined;
var problemsPanelOptions = { showErrors: true, showWarnings: true };
const PROBLEMSPANEL_CUSTOMPROPERTY_TYPE = 0;
const PROBLEMSPANEL_CUSTOMPROPERTY_TYPE0_FILEHEADER_URL = 1;
const PROBLEMSPANEL_CUSTOMPROPERTY_TYPE1_DIAGNOSTIC_LINENUM = 1;
const PROBLEMSPANEL_CUSTOMPROPERTY_TYPE1_DIAGNOSTIC_CHARNUM = 2;
const PROBLEMSPANEL_CUSTOMPROPERTY_TYPE1_DIAGNOSTIC_SEVERITY = 3;
const _PROBLEMSPANEL_CUSTOMPROPERTY_MAXCOUNT = 4;
const PROBLEMSPANEL_CUSTOMPROPERTY_TYPE0_FILEHEADER = 0;
const PROBLEMSPANEL_CUSTOMPROPERTY_TYPE1_DIAGNOSTIC = 1;
function generateCopyPasteTextForProblem(e, t) {
  if (!e) return;
  var i = e
    .getParentNodeInfo()
    .getCustomData(PROBLEMSPANEL_CUSTOMPROPERTY_TYPE0_FILEHEADER_URL);
  if (!i) return;
  var n = e.getCustomData(PROBLEMSPANEL_CUSTOMPROPERTY_TYPE);
  let a;
  switch (n) {
    case PROBLEMSPANEL_CUSTOMPROPERTY_TYPE0_FILEHEADER:
      return;
      break;
    case PROBLEMSPANEL_CUSTOMPROPERTY_TYPE1_DIAGNOSTIC:
      a = e.getCaption();
      break;
  }
  var o = e.getCustomData(
    PROBLEMSPANEL_CUSTOMPROPERTY_TYPE1_DIAGNOSTIC_SEVERITY
  );
  var s = e.getCustomData(
    PROBLEMSPANEL_CUSTOMPROPERTY_TYPE1_DIAGNOSTIC_LINENUM
  );
  var r = e.getCustomData(
    PROBLEMSPANEL_CUSTOMPROPERTY_TYPE1_DIAGNOSTIC_CHARNUM
  );
  if (t && o !== 1) return;
  a =
    (o === 1 ? "{ERROR} " : "{WARNING} ") +
    i +
    " [" +
    (s + 1) +
    "," +
    (r + 1) +
    "]: " +
    a;
  return a;
}
class _problemsPanel {
  constructor(e, t) {
    var i = _PROBLEMSPANEL_CUSTOMPROPERTY_MAXCOUNT;
    this.id = 0;
    this.tree = new virtualTreeView(
      e,
      "PROBLEMS",
      "twinbasic-problems:",
      false,
      i,
      "--problems",
      t
    );
    this.tree.showFolderIcons = false;
    this.tree.autoExpandOnSelect = false;
    this.tree.showTooltips = true;
    this.tree.additionalFolderClassNames = "testTree";
    this.tree.emptyFolderText = "";
    this.tree.renderDomNode = (e) => {
      var t = e.getCustomData(PROBLEMSPANEL_CUSTOMPROPERTY_TYPE);
      let i;
      switch (t) {
        case PROBLEMSPANEL_CUSTOMPROPERTY_TYPE0_FILEHEADER:
          if (e.isExpanded()) {
            i =
              "<div class='problemNodeGroupIcon iconCollapse14' onclick='toggleProblemNode(event)'></div>";
          } else {
            i =
              "<div class='problemNodeGroupIcon iconExpand14' onclick='toggleProblemNode(event)'></div>";
          }
          var n = e.getCustomData(
            PROBLEMSPANEL_CUSTOMPROPERTY_TYPE0_FILEHEADER_URL
          );
          return (
            "<div class='problemNodeGroup' title='" +
            n +
            "'>" +
            i +
            e.getCaption() +
            "</div>"
          );
        case PROBLEMSPANEL_CUSTOMPROPERTY_TYPE1_DIAGNOSTIC:
          var a = e.getCustomData(
            PROBLEMSPANEL_CUSTOMPROPERTY_TYPE1_DIAGNOSTIC_SEVERITY
          );
          var o = e.getCustomData(
            PROBLEMSPANEL_CUSTOMPROPERTY_TYPE1_DIAGNOSTIC_LINENUM
          );
          var s = e.getCustomData(
            PROBLEMSPANEL_CUSTOMPROPERTY_TYPE1_DIAGNOSTIC_CHARNUM
          );
          if (a === 1) {
            i = "<div class='problemNodeIcon errorIconRed'></div>";
          } else {
            i = "<div class='problemNodeIcon warningIconYellow'></div>";
          }
          return (
            "<div class='problemNodeItem'>" +
            i +
            e.getCaption() +
            "<div class='problemNodePos'>[" +
            (o + 1) +
            "," +
            (s + 1) +
            "]</div>" +
            "</div>"
          );
      }
    };
    this.tree.onDblClickNode = (e) => {
      var t = e.getCustomData(PROBLEMSPANEL_CUSTOMPROPERTY_TYPE);
      switch (t) {
        case PROBLEMSPANEL_CUSTOMPROPERTY_TYPE0_FILEHEADER:
          e.toggleExpanded();
          this.tree.updateVisibleNodesList();
          break;
        case PROBLEMSPANEL_CUSTOMPROPERTY_TYPE1_DIAGNOSTIC:
          var i = e
            .getParentNodeInfo()
            .getCustomData(PROBLEMSPANEL_CUSTOMPROPERTY_TYPE0_FILEHEADER_URL);
          var n = e.getCustomData(
            PROBLEMSPANEL_CUSTOMPROPERTY_TYPE1_DIAGNOSTIC_LINENUM
          );
          var a = e.getCustomData(
            PROBLEMSPANEL_CUSTOMPROPERTY_TYPE1_DIAGNOSTIC_CHARNUM
          );
          var o = fs.tree.resolvePath("twinbasic:" + i);
          openEditors.openFile(o, false, false, false, n + 1, a + 1);
          break;
      }
    };
    this.tree.onClickNode = (e) => {
      var t = e.getCustomData(PROBLEMSPANEL_CUSTOMPROPERTY_TYPE);
      switch (t) {
        case PROBLEMSPANEL_CUSTOMPROPERTY_TYPE1_DIAGNOSTIC:
          var i = e
            .getParentNodeInfo()
            .getCustomData(PROBLEMSPANEL_CUSTOMPROPERTY_TYPE0_FILEHEADER_URL);
          var n = e.getCustomData(
            PROBLEMSPANEL_CUSTOMPROPERTY_TYPE1_DIAGNOSTIC_LINENUM
          );
          var a = e.getCustomData(
            PROBLEMSPANEL_CUSTOMPROPERTY_TYPE1_DIAGNOSTIC_CHARNUM
          );
          var o = fs.tree.resolvePath("twinbasic:" + i);
          openEditors.openFile(
            o,
            liveIDEOptions["previewDocs"] ? true : false,
            false,
            false,
            n + 1,
            a + 1
          );
          break;
      }
    };
    this.tree.onRightClickNode = (e, t, i) => {
      showContextMenu(undefined, t, i, [
        {
          name: "Copy",
          action: () => {
            var t = generateCopyPasteTextForProblem(e);
            if (t === undefined) t = "";
            navigator.clipboard.writeText(t);
          },
        },
        {
          name: "Copy All",
          action: () => {
            let e =
              "twinBASIC (" + tbVersionInfo + ") compilation error report:\r\n";
            var t = 1;
            while (1) {
              t = this.tree.view.data.getNextVisibleNode2(t, false, true);
              if (!t) break;
              var i = this.tree.view.data.generateNodeInfo(t);
              var n = generateCopyPasteTextForProblem(i);
              if (n) e += " " + n + "\r\n";
            }
            navigator.clipboard.writeText(e);
          },
        },
        {
          name: "Copy All Errors",
          action: () => {
            let e =
              "twinBASIC (" + tbVersionInfo + ") compilation error report:\r\n";
            var t = 1;
            while (1) {
              t = this.tree.view.data.getNextVisibleNode2(t, false, true);
              if (!t) break;
              var i = this.tree.view.data.generateNodeInfo(t);
              var n = generateCopyPasteTextForProblem(i, true);
              if (n) e += " " + n + "\r\n";
            }
            navigator.clipboard.writeText(e);
          },
        },
        {},
        {
          name: "Collapse all",
          action: () => {
            var e = 1;
            while (1) {
              e = this.tree.view.data.getNextVisibleNode2(e, false, true);
              if (!e) break;
              var t = this.tree.view.data.generateNodeInfo(e);
              var i = t.getCustomData(PROBLEMSPANEL_CUSTOMPROPERTY_TYPE);
              if (i == PROBLEMSPANEL_CUSTOMPROPERTY_TYPE0_FILEHEADER) {
                t.collapse();
              }
            }
          },
        },
        {
          name: "Expand all",
          action: () => {
            var e = 1;
            while (1) {
              e = this.tree.view.data.getNextVisibleNode2(e, false, true);
              if (!e) break;
              var t = this.tree.view.data.generateNodeInfo(e);
              var i = t.getCustomData(PROBLEMSPANEL_CUSTOMPROPERTY_TYPE);
              if (i == PROBLEMSPANEL_CUSTOMPROPERTY_TYPE0_FILEHEADER) {
                t.expand();
              }
            }
          },
        },
      ]);
    };
    this.tree.init();
    if (!t) {
      var n = createDOMElement(this.tree.sectionHeader, "div", "flexDiv", "");
      n.innerHTML =
        "<div id='statusErrors' title='Total Error Count' onclick='toggleProblemsErrors()'><div class='statusIcon errorIcon'></div><div id='errorCount'>0</div></div>" +
        "<div id='statusWarnings' title='Total Warning Count' onclick='toggleProblemsWarnings()'><div class='statusIcon warningIcon'></div><div id='warningCount'>0</div></div>";
    }
    this.tree.finishedInit();
  }
  syncFileProblems(e) {
    var t = false;
    this.tree.view.data.startMultiUpdate();
    try {
      var i = () => {
        var i =
          e.cachedDiagnostics_errorCount + e.cachedDiagnostics_warningCount;
        if (!e.problemNode) {
          if (i == 0) {
            t = true;
            return;
          }
          e.problemNode = this.tree.view.data.addSubNode(
            this.tree.view.data.rootFolder,
            e.name,
            0,
            e.getFullPath()
          );
        } else {
          if (i == 0) {
            this.tree.view.data.deleteNode(e.problemNode);
            e.problemNode = undefined;
            return;
          } else {
            this.tree.view.data.deleteNodeChildren(e.problemNode);
          }
        }
        if (e.cachedDiagnostics) {
          e.cachedDiagnostics.forEach((t) => {
            this.tree.view.data.addSubNode(
              e.problemNode,
              t.message,
              1,
              t.range.start.line,
              t.range.start.character,
              t.severity,
              t.severity == 1,
              t.severity == 2
            );
          });
        }
      };
      i();
    } catch (e) {}
    if (t) {
      this.tree.view.data.endMultiUpdateNoChanges();
    } else {
      this.tree.view.data.endMultiUpdate();
    }
  }
}
function toggleProblemNode(e) {
  problemsPanel.tree.view.toggleExpanded(
    e.target.parentNode.parentNode.nodeVisibleIndex
  );
  e.stopPropagation();
}
function createProblemsPanel(e, t) {
  if (problemsPanel) return problemsPanel;
  problemsPanel = new _problemsPanel(e, t);
}
function toggleProblemsErrors(e) {
  problemsPanelOptions.showErrors = problemsPanelOptions.showErrors
    ? false
    : true;
  resyncProblemsPanelOptions();
}
function toggleProblemsWarnings(e) {
  problemsPanelOptions.showWarnings = problemsPanelOptions.showWarnings
    ? false
    : true;
  resyncProblemsPanelOptions();
}
function resyncProblemsPanelOptions() {
  if (problemsPanelOptions.showErrors) {
    statusErrorsDiv.classList.remove("statusUnselected");
    problemsPanel.tree.view.data.hideGroup1 = false;
  } else {
    statusErrorsDiv.classList.add("statusUnselected");
    problemsPanel.tree.view.data.hideGroup1 = true;
  }
  if (problemsPanelOptions.showWarnings) {
    statusWarningsDiv.classList.remove("statusUnselected");
    problemsPanel.tree.view.data.hideGroup2 = false;
  } else {
    statusWarningsDiv.classList.add("statusUnselected");
    problemsPanel.tree.view.data.hideGroup2 = true;
  }
  problemsPanel.tree.view.data.updateVisibleNodesList();
}
var layoutChangesPending = 1;
var hiddenDiv;
Array.prototype.peek = function () {
  if (this.length === 0) {
    throw new Error("out of bounds");
  }
  return this[this.length - 1];
};
function initMisc() {
  hiddenDiv = createDOMElement(undefined, "div");
}
function createDOMElement(e, t, i, n) {
  var a = document.createElement(t);
  if (i) a.classList = i;
  if (n) a.innerText = n;
  if (t === "input") a.spellcheck = false;
  if (e) e.appendChild(a);
  return a;
}
function freezeLayoutChanges() {
  layoutChangesPending++;
  if (layoutChangesPending == 1) {
    document.getElementById("bodyInner").classList.add("displayNone");
  }
}
function unfreezeLayoutChanges() {
  layoutChangesPending--;
  if (layoutChangesPending == 0) {
    document.getElementById("bodyInner").classList.remove("displayNone");
  }
}
function doLayoutChanges(e) {
  freezeLayoutChanges();
  try {
    e();
  } catch (e) {}
  unfreezeLayoutChanges();
}
function copyToClipboard(e) {
  alert(e.toString());
}
function bufferToBase64Async(e, t) {
  var i = new Blob([e], { type: "application/octet-binary" });
  var n = new FileReader();
  n.onload = function () {
    var e = n.result;
    var i = e.substr(e.indexOf(",") + 1);
    t(i);
  };
  n.readAsDataURL(i);
}
function base64ToBufferAsync(e, t) {
  var i = "data:application/octet-binary;base64," + e;
  fetch(i)
    .then((e) => e.arrayBuffer())
    .then((e) => {
      t(e);
    });
}
function readBinaryFile(e, t) {
  var i = new XMLHttpRequest();
  i.responseType = "arraybuffer";
  i.open("GET", e, true);
  i.onreadystatechange = function () {
    if (i.readyState === 4) {
      if (i.status === 200 || i.status == 0) {
        debugger;
        var e = i.response;
        t(e);
      }
    }
  };
  i.send(null);
}
function displayVirtualFile(e) {
  var t;
  var i = {
    name: e.displayName,
    fileNode: { toolTip: e.tooltip },
    fileHandler: {
      activated(i, n, a, o) {
        i.type = "VirtualPreview";
        statusLineCol.classList.add("hide");
        codePanelMainInnerMonacoContainer.classList.add("hide");
        codePanelDropDownContainer.classList.add("hideNotCodeEditor");
        changedSize();
        i.domObject_CloseButton.className = "tabItemIconRight";
        if (!t) {
          t = createDOMElement(
            codePanelMainInner,
            "div",
            "virtualDocumentContainer"
          );
          t.innerHTML = e.html;
          if (e.onCreateDom) e.onCreateDom(t);
        } else {
          t.classList.remove("hide");
        }
        outlinePanel.syncSymbols([]);
      },
      onFocus(e) {
        t.focus();
      },
      onReveal(e, t, i, n) {},
      isDirty(e) {
        return false;
      },
      deactivated(e) {
        t.classList.add("hide");
      },
      save(e) {},
      closing(e, t, i) {
        i();
      },
      closed(e) {
        codePanelMainInner.removeChild(t);
        t = undefined;
      },
    },
    tree: openEditors.tree,
  };
  i.tabElement = openEditors.createTabElement(i, false);
  openEditors.changeSelectedEditor(i, false, false, false);
  changedSize();
}
function displayVirtualFileInMonaco(e) {
  var t;
  var i = {
    name: e.displayName,
    fileNode: { toolTip: e.tooltip },
    fileHandler: {
      activated(t, i, n, a) {
        t.type = "VirtualMonaco";
        clearEditor();
        editor.updateOptions({ glyphMargin: false, readOnly: true });
        if (!t.monacoModelInstance) {
          t.monacoModelInstance = monaco.editor.createModel("", "twinbasic");
          if (liveIDEOptions["tabSize"])
            t.monacoModelInstance.updateOptions({
              tabSize: liveIDEOptions["tabSize"],
            });
        }
        editor.setModel(t.monacoModelInstance);
        monaco.editor.setModelLanguage(t.monacoModelInstance, e.lang);
        lineNum.innerText = 1;
        columnNum.innerText = 1;
        if (t.monacoViewState) {
          editor.restoreViewState(t.monacoViewState);
        }
        statusLineCol.classList.remove("hide");
        codePanelMainInnerMonacoContainer.classList.remove("hide");
        codePanelDropDownContainer.classList.add("hideNotCodeEditor");
        changedSize();
        if (!i) editor.focus();
        t.monacoModelInstance.setValue(e.text);
        t.domObject_CloseButton.className = "tabItemIconRight";
      },
      deactivated(e) {
        e.monacoViewState = editor.saveViewState();
      },
      undo(e) {},
      redo(e) {},
      isDirty(e) {
        return false;
      },
      save(e, t) {
        if (t) t();
      },
      resyncToFileSystem(e) {},
      closing(e, t, i) {
        if (i) i();
      },
      closed(e) {},
      onFocus(e) {
        editor.focus();
      },
      gotFileData(e, t) {
        debugger;
      },
    },
    tree: openEditors.tree,
  };
  i.tabElement = openEditors.createTabElement(i, false);
  openEditors.changeSelectedEditor(i, false, false, false);
  changedSize();
}
function generateUUID() {
  return "{" + generateUUID2() + "}";
}
function generateUUID2() {
  var e = new Date().getTime();
  var t = (performance && performance.now && performance.now() * 1e3) || 0;
  return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (i) {
    var n = Math.random() * 16;
    if (e > 0) {
      n = (e + n) % 16 | 0;
      e = Math.floor(e / 16);
    } else {
      n = (t + n) % 16 | 0;
      t = Math.floor(t / 16);
    }
    return (i === "x" ? n : (n & 3) | 8).toString(16).toUpperCase();
  });
}
function sortObjectByKeys(e, t) {
  return Object.keys(e)
    .sort(t)
    .reduce((t, i) => ((t[i] = e[i]), t), {});
}
function JSONstringifyOrdered(e, t) {
  var i = [];
  var n = {};
  JSON.stringify(e, function (e, t) {
    if (!(e in n)) {
      i.push(e);
      n[e] = null;
    }
    return t;
  });
  i.sort();
  return JSON.stringify(e, i, t);
}
function parseNumeric(e, t) {
  var i = parseInt(e);
  if (isNaN(i)) i = t;
  if (i === undefined) i = 0;
  return i;
}
function parseJson(e, t) {
  try {
    return JSON.parse(e);
  } catch (e) {
    return t;
  }
}
function JSONfn_stringify(e) {
  return JSON.stringify(e, (e, t) =>
    typeof t === "function" ? "~" + t.toString() : t
  );
}
function JSONfn_parse(str) {
  return JSON.parse(str, (key, value) => {
    if (typeof value !== "string") return value;
    return value.substring(0, 1) === "~"
      ? eval(eval(`function ${value.substring(1)}; ${key}`))
      : value;
  });
}
function serverHttpsGetUtf8(e, t, i) {
  const n = new XMLHttpRequest();
  n.open("GET", "https://www.everythingaccess.com" + e);
  n.overrideMimeType("text/plain; charset=utf-8");
  n.send();
  n.onreadystatechange = (e) => {
    if (n.readyState === 4) {
      if (n.status === 200) {
        t(n.responseText);
      } else {
        i();
      }
    }
  };
}
function serverHttpsGetBinary(e, t, i) {
  const n = new XMLHttpRequest();
  n.open("GET", "https://www.everythingaccess.com" + e);
  n.responseType = "arraybuffer";
  n.send();
  n.onreadystatechange = (e) => {
    if (n.readyState === 4) {
      if (n.status === 200) {
        t(n.response);
      } else {
        i();
      }
    }
  };
}
function TEXTtoHTML(e) {
  e = e.replace(/&/g, "&amp;");
  e = e.replace(/</g, "&lt;");
  e = e.replace(/>/g, "&gt;");
  e = e.replace(/\\/g, "&#92;");
  return e;
}
function intToUint8Array(e) {
  return Uint8Array.of(
    (e & 255) >> 0,
    (e & 65280) >> 8,
    (e & 16711680) >> 16,
    (e & 4278190080) >> 24
  );
}
function syncWait(e) {
  var t = Date.now();
  while (Date.now() - t < e) {}
}
function createWebsocketWithFallback(e) {
  return new WebSocket(e);
}
function deepclone(e) {
  if (e === null || "clonePreventRecursion" in e) return e;
  var t = {};
  for (var i in e) {
    e["clonePreventRecursion"] = null;
    let n = e[i];
    t[i] = typeof n === "object" ? deepclone(n) : n;
    delete e["clonePreventRecursion"];
  }
  return t;
}
function shallowclone(e) {
  var t = {};
  for (var i in e) {
    let n = e[i];
    t[i] = typeof n === "object" ? null : n;
  }
  return t;
}
function copyEvent(e) {
  let t = shallowclone(e);
  if (e.target) t.target = { id: e.target.id, value: e.target.value };
  return t;
}
function raiseEvent(e, t, i, ...n) {
  var a = t.target.parentNode;
  while (!a.rootEventHandler) a = a.parentNode;
  var o = 0;
  while (o < n.length) {
    t["customData" + o] = n[o];
    o += 1;
  }
  if (a.rootEventHandler) {
    a.rootEventHandler[e](t);
  }
  if (i) t.stopPropagation();
}
var leftPanel;
var rightPanel;
var centerInnerPanel;
var isRestoringPanelConfigurations = false;
var isRestoringPanelConfigurations2 = false;
var floatingToolWindowsData = {};
var panelLayout = {};
async function initLayout(e) {
  try {
    panelLayout = JSON.parse(await hostAppObject.GetIDESetting("LAYOUT"));
  } catch (e) {}
  if (!panelLayout) panelLayout = {};
  if (typeof panelLayout !== "object") panelLayout = {};
  floatingToolWindowsData = panelLayout.floatingToolWindows;
  if (typeof floatingToolWindowsData !== "object") floatingToolWindowsData = {};
  e();
}
function assignToPanel(e, t, i, n) {
  if (t) {
    e = t._this;
    if (!t.parentNode.isVerticalPanel) {
      t.parentNode.parentNode.removeChild(t.parentNode);
    }
    t.parentNode.removeChild(t);
    e.panelDiv.layoutChanged(e.panelDiv);
  }
  e.panelDiv = i;
  e.sectionHeader = e.panelDiv.addPanelSection(
    e.friendlyName,
    e.panelDiv,
    "sectionHeader",
    false,
    n
  );
  e.sectionHeader._this = e;
  e.sectionHeader.sectionRoot = e.sectionRoot;
  if (e.sectionHeader.restoreCustomSize) e.sectionHeader.restoreCustomSize();
  e.sectionRoot.tabIndex = "0";
  e.sectionRoot.ondragover = (t) => {
    onDragPanelSectionHover(t, e.sectionHeader);
  };
  e.sectionRoot.ondrop = (e) => {
    onDragPanelSectionDropped(e);
  };
  e.sectionHeader.sectionRoot = e.sectionRoot;
  if (!isRestoringPanelConfigurations) {
    e.sectionHeader.sectionRoot.style = "";
  }
  if (e.sectionExpander) {
    e.sectionHeader.appendChild(e.sectionExpander);
    if (e.panelDiv.isVerticalPanel && !e.panelDiv.isToolWindow) {
      e.sectionExpander.classList.remove("hide");
    } else {
      e.sectionExpander.classList.add("hide");
      e.sectionRoot.classList.remove("sectionHidden");
      e.sectionHeader.classList.remove("sectionHeaderCollapsed");
    }
  }
  e.sectionHeader.appendChild(e.sectionHeaderInner);
  if (n && e.panelDiv.isVerticalPanel) {
    if (e.filterTextOuter)
      e.sectionHeader.parentNode.insertBefore(e.filterTextOuter, n);
    e.sectionHeader.parentNode.insertBefore(e.sectionRoot, n);
  } else {
    if (e.filterTextOuter)
      e.sectionHeader.parentNode.appendChild(e.filterTextOuter);
    e.sectionHeader.parentNode.appendChild(e.sectionRoot);
  }
  if (e.sectionExpander)
    e.sectionExpander.onclick = (t) => {
      toggleSectionExpansion(e.sectionRoot, e.sectionHeader, e.sectionBody);
    };
  if (t) {
    while (t.childNodes.length) {
      var a = t.childNodes[0];
      if (a.isResizer) {
        t.removeChild(a);
      } else {
        e.sectionHeader.appendChild(a);
      }
    }
  }
  e.panelDiv.layoutChanged(e.panelDiv);
  if (t) {
    savePanelsConfiguration();
  }
}
function restorePanelConfiguration(e, t) {
  var i = e.offsetHeight;
  isRestoringPanelConfigurations = true;
  try {
    t.forEach((t) => {
      switch (t) {
        case "PROJECT EXPLORER":
          createFileExplorer(e);
          break;
        case "OPEN EDITORS":
          createOpenEditors(e);
          break;
        case "CALL STACK":
          createCallStackPanel(e);
          break;
        case "VARIABLES":
          createVariablesPanel(e);
          break;
        case "WATCH":
          createWatchPanel(e);
          break;
        case "DEBUG CONSOLE":
          createDebugConsole(e);
          break;
        case "PROBLEMS":
          createProblemsPanel(e);
          break;
        case "OUTLINE":
          createOutlinePanel(e);
          break;
        case "HISTORY":
          createHistoryPanel(e);
          break;
        case "PACKAGE PUBLISHING":
          createPackageManagerPanel(e);
          break;
      }
    });
  } catch (e) {}
  isRestoringPanelConfigurations = false;
}
function restorePanelsConfiguration() {
  isRestoringPanelConfigurations2 = true;
  leftPanel.addPanelSection(
    "{psuedo-begin}",
    leftPanel,
    "sectionHeader invisible2",
    true
  );
  rightPanel.addPanelSection(
    "{psuedo-begin}",
    rightPanel,
    "sectionHeader invisible2",
    true
  );
  centerInnerPanel.addPanelSection(
    "{psuedo-begin}",
    centerInnerPanel,
    "sectionHeader invisible2",
    true
  );
  if (panelLayout.panelsConfigration) {
    try {
      restorePanelConfiguration(
        leftPanel,
        panelLayout.panelsConfigration.leftPanel
      );
      restorePanelConfiguration(
        rightPanel,
        panelLayout.panelsConfigration.rightPanel
      );
      restorePanelConfiguration(
        centerInnerPanel,
        panelLayout.panelsConfigration.centerInnerPanel
      );
    } catch (e) {}
  }
  createFileExplorer(leftPanel);
  createOpenEditors(leftPanel);
  createOutlinePanel(leftPanel);
  createHistoryPanel(leftPanel);
  createProblemsPanel(leftPanel);
  createCallStackPanel(rightPanel);
  createVariablesPanel(rightPanel);
  createWatchPanel(rightPanel);
  createDebugConsole(centerInnerPanel);
  createPackageManagerPanel(rightPanel);
  leftPanel.addPanelSection(
    "{psuedo-end}",
    leftPanel,
    "sectionHeader invisible2",
    true
  );
  rightPanel.addPanelSection(
    "{psuedo-end}",
    rightPanel,
    "sectionHeader invisible2",
    true
  );
  centerInnerPanel.addPanelSection(
    "{psuedo-end}",
    centerInnerPanel,
    "sectionHeader invisible2",
    true
  );
  leftPanel.layoutChanged(leftPanel);
  rightPanel.layoutChanged(rightPanel);
  centerInnerPanel.layoutChanged(centerInnerPanel);
  isRestoringPanelConfigurations2 = false;
}
function savePanelsConfiguration() {
  if (isRestoringPanelConfigurations || isRestoringPanelConfigurations2) return;
  var e = [];
  for (let i = 0; i < leftPanel.childNodes.length; i++) {
    var t = leftPanel.childNodes[i];
    if (t.isRealPanelSection) {
      e.push(t.panelId);
      panelLayout[t.panelId] = t.sectionRoot.style.flexBasis
        ? parseInt(t.sectionRoot.style.flexBasis)
        : undefined;
      panelLayout[t.panelId + "-collapsed"] = t.classList.contains(
        "sectionHeaderCollapsed"
      )
        ? true
        : false;
    }
  }
  var i = [];
  for (let e = 0; e < rightPanel.childNodes.length; e++) {
    var t = rightPanel.childNodes[e];
    if (t.isRealPanelSection) {
      debugger;
      i.push(t.panelId);
      panelLayout[t.panelId] = t.sectionRoot.style.flexBasis
        ? parseInt(t.sectionRoot.style.flexBasis)
        : undefined;
      panelLayout[t.panelId + "-collapsed"] = t.classList.contains(
        "sectionHeaderCollapsed"
      )
        ? true
        : false;
    }
  }
  var n = [];
  for (let e = 0; e < centerInnerPanel.childNodes.length; e++) {
    var t = centerInnerPanel.childNodes[e];
    if (t.isRealPanelSection) {
      n.push(t.panelId);
      panelLayout[t.panelId] = t.style.minWidth
        ? parseInt(t.style.minWidth)
        : undefined;
      panelLayout[t.panelId + "-collapsed"] = t.innerDiv.classList.contains(
        "sectionHeaderCollapsed"
      )
        ? true
        : false;
    }
  }
  panelLayout.panelsConfigration = {
    leftPanel: e,
    rightPanel: i,
    centerInnerPanel: n,
  };
  panelLayout.leftPanel = parseInt(leftPanel.style.flexBasis);
  panelLayout.rightPanel = parseInt(rightPanel.style.flexBasis);
  panelLayout.centerInnerPanel = parseInt(centerInnerPanel.style.flexBasis);
  panelLayout.floatingToolWindows = floatingToolWindowsData;
  hostAppObject.SaveIDESetting("LAYOUT", JSON.stringify(panelLayout));
}
function initPanels() {
  leftPanel = document.getElementById("leftPanel");
  rightPanel = document.getElementById("rightPanel");
  centerInnerPanel = document.getElementById("centerInnerPanel");
  leftPanel.isVerticalPanel = true;
  rightPanel.isVerticalPanel = true;
  var e = document.getElementById("leftPanelResizer");
  e.onclick = (e) => {
    e.stopPropagation();
    return false;
  };
  e.onmousedown = (e) => {
    if (e.button === 0) {
      var t = leftPanel.offsetWidth;
      var i = (i) => {
        var n = t + (i.pageX - e.pageX);
        if (n < 50) return;
        leftPanel.style.flexBasis = n + "px";
        changedSize();
      };
      var n = (a) => {
        document.removeEventListener("mousemove", i);
        document.removeEventListener("mouseup", n);
        var o = t + (a.pageX - e.pageX);
        if (o < 50) return;
        leftPanel.style.flexBasis = o + "px";
        changedSize();
        savePanelsConfiguration();
      };
      document.addEventListener("mousemove", i);
      document.addEventListener("mouseup", n);
    }
  };
  var t = document.getElementById("rightPanelResizer");
  t.onclick = (e) => {
    e.stopPropagation();
    return false;
  };
  t.onmousedown = (e) => {
    if (e.button === 0) {
      var t = rightPanel.offsetWidth;
      var i = (i) => {
        var n = t - (i.pageX - e.pageX);
        if (n < 50) return;
        rightPanel.style.flexBasis = n + "px";
        changedSize();
      };
      var n = (a) => {
        document.removeEventListener("mousemove", i);
        document.removeEventListener("mouseup", n);
        var o = t - (a.pageX - e.pageX);
        if (o < 50) return;
        rightPanel.style.flexBasis = o + "px";
        changedSize();
        savePanelsConfiguration();
      };
      document.addEventListener("mousemove", i);
      document.addEventListener("mouseup", n);
    }
  };
  var i = document.getElementById("centerPanelResizer");
  i.onclick = (e) => {
    e.stopPropagation();
    return false;
  };
  i.onmousedown = (e) => {
    if (e.button === 0) {
      var t = centerInnerPanel.offsetHeight;
      var i = (i) => {
        var n = t - (i.pageY - e.pageY);
        if (n < 50) return;
        centerInnerPanel.style.flexBasis = n + "px";
        changedSize();
      };
      var n = (a) => {
        document.removeEventListener("mousemove", i);
        document.removeEventListener("mouseup", n);
        var o = t - (a.pageY - e.pageY);
        if (o < 50) return;
        centerInnerPanel.style.flexBasis = o + "px";
        changedSize();
        savePanelsConfiguration();
      };
      document.addEventListener("mousemove", i);
      document.addEventListener("mouseup", n);
    }
  };
  leftPanel.countOfSections = 0;
  leftPanel.addPanelSection = addVerticalPanelSection;
  leftPanel.layoutChanged = verticalPanelLayoutChanged;
  rightPanel.countOfSections = 0;
  rightPanel.addPanelSection = addVerticalPanelSection;
  rightPanel.layoutChanged = verticalPanelLayoutChanged;
  centerInnerPanel.countOfSections = 0;
  centerInnerPanel.addPanelSection = addHorizontalPanelSection;
  centerInnerPanel.layoutChanged = horizontalPanelLayoutChanged;
  var n = panelLayout["leftPanel"];
  if (n) {
    try {
      leftPanel.style.flexBasis = parseInt(n) + "px";
    } catch (e) {}
  }
  var a = panelLayout["rightPanel"];
  if (a) {
    try {
      rightPanel.style.flexBasis = parseInt(a) + "px";
    } catch (e) {}
  }
  var o = panelLayout["centerInnerPanel"];
  if (o) {
    try {
      centerInnerPanel.style.flexBasis = parseInt(o) + "px";
    } catch (e) {}
  }
}
function makeDraggablePanelHeader(e) {
  e.draggable = true;
  e.ondragstart = (t) => {
    onDragPanelSectionStart(t, e);
  };
  e.ondragover = (t) => {
    onDragPanelSectionHover(t, e, true);
  };
  e.ondragend = (t) => {
    onDragPanelSectionEnd(t, e);
  };
  e.ondrop = (e) => {
    onDragPanelSectionDropped(e);
  };
}
function updateInterPanelLinks(e) {
  var t = undefined;
  var i = undefined;
  for (let a = 0; a < e.childNodes.length; a++) {
    var n = e.childNodes[a];
    if (n.isPanelSection) {
      if (e.isVerticalPanel) {
        n.previousPanelSection = t;
        t = n;
        if (i) i.nextPanelSection = n;
        i = n;
      } else {
        n.innerDiv.previousPanelSection = t;
        t = n.innerDiv;
        if (i) i.nextPanelSection = n.innerDiv;
        i = n.innerDiv;
      }
    }
  }
}
function areAllSectionsFixedHeight(e) {
  for (let i = 0; i < e.childNodes.length; i++) {
    var t = e.childNodes[i];
    if (t.isRealPanelSection) {
      if (!t.sectionRoot.style.flexBasis) {
        return false;
      }
    }
  }
  return true;
}
function areAllSectionsFixedWidth(e) {
  for (let i = 0; i < e.childNodes.length; i++) {
    var t = e.childNodes[i];
    if (t.isRealPanelSection) {
      if (!t.style.minWidth) {
        return false;
      }
    }
  }
  return true;
}
function getPanelSectionsInfo(e, t) {
  var i = 0;
  var n = undefined;
  var a = undefined;
  var o = undefined;
  var s = undefined;
  for (let l = 0; l < e.childNodes.length; l++) {
    var r = e.childNodes[l];
    if (r.isPanelSection) {
      if (!o) o = r;
      n = r;
      i += 1;
      if (t) r.style = "";
    }
    if (r.isRealPanelSection) {
      s = r;
      if (t) r.style = "";
    }
    if (r.isEmptyPsuedoElement) {
      a = r;
    }
  }
  return {
    count: i,
    firstPanelSection: o,
    lastPanelSection: n,
    lastRealPanelSection: s,
    emptyPsuedoElement: a,
  };
}
function verticalPanelLayoutChanged(e) {
  var t = getPanelSectionsInfo(e, true);
  if (t.emptyPsuedoElement) {
    e.removeChild(t.emptyPsuedoElement);
  }
  if (!isRestoringPanelConfigurations && t.count == 2) {
    var i = createDOMElement(e, "div", "");
    i.isEmptyPsuedoElement = true;
    i.style.flexGrow = "1";
    i.style.flexShrink = "1";
    i.style.background =
      "repeating-linear-gradient( 45deg, #202021, #333335 10px, #4b4b4d 10px, #1a1a1a 20px)";
    e.insertBefore(i, t.lastPanelSection);
    i.ondragover = (e) => {
      if (currentDragType !== DRAG_PANEL_SECTION) return;
      e.preventDefault();
      e.dataTransfer.dropEffect = "move";
      currentDropZone = t.firstPanelSection;
      currentDropZone.resizerDiv.classList.add("panelMoveTarget");
      currentDropZone.classList.add("panelMoveTargetParent");
    };
    i.ondrop = (i) => {
      if (currentDragType !== DRAG_PANEL_SECTION) return;
      i.preventDefault();
      assignToPanel(undefined, startDropZone, e, t.lastPanelSection);
    };
  }
  updateInterPanelLinks(e);
  if (
    !isRestoringPanelConfigurations &&
    t.lastRealPanelSection &&
    areAllSectionsFixedHeight(e)
  ) {
    t.lastRealPanelSection.sectionRoot.style.flexGrow = "1";
    t.lastRealPanelSection.sectionRoot.style.flexShrink = "1";
    t.lastRealPanelSection.sectionRoot.style.flexBasis = "";
  }
  savePanelsConfiguration();
}
function horizontalPanelLayoutChanged(e) {
  var t = getPanelSectionsInfo(e, false);
  if (t.emptyPsuedoElement) {
    e.removeChild(t.emptyPsuedoElement);
  }
  if (!isRestoringPanelConfigurations && !t.lastRealPanelSection) {
    var i = createDOMElement(e, "div", "");
    i.isEmptyPsuedoElement = true;
    i.style.flexGrow = "1";
    i.style.flexShrink = "1";
    i.style.background =
      "repeating-linear-gradient( 45deg, #202021, #333335 10px, #4b4b4d 10px, #1a1a1a 20px)";
    e.insertBefore(i, t.lastPanelSection);
    i.ondragover = (e) => {
      e.preventDefault();
      e.dataTransfer.dropEffect = "move";
      currentDropZone = t.firstPanelSection;
      currentDropZone.resizerDiv.classList.add("panelMoveTarget");
      currentDropZone.classList.add("panelMoveTargetParent");
    };
    i.ondrop = (i) => {
      i.preventDefault();
      assignToPanel(undefined, startDropZone, e, t.lastPanelSection);
    };
  }
  if (
    !isRestoringPanelConfigurations &&
    t.lastRealPanelSection &&
    areAllSectionsFixedWidth(e)
  ) {
    t.lastRealPanelSection.style.flexGrow = "1";
    t.lastRealPanelSection.style.flexShrink = "1";
    t.lastRealPanelSection.style.minWidth = "";
    t.lastRealPanelSection.style.maxWidth = "";
  }
  updateInterPanelLinks(e);
  savePanelsConfiguration();
}
function addVerticalPanelSection(e, t, i, n, a) {
  t.countOfSections++;
  var o = createDOMElement(t, "div", i);
  if (a) {
    t.insertBefore(o, a);
  }
  if (!n) o.isRealPanelSection = true;
  o.isPanelSection = true;
  updateInterPanelLinks(t);
  if (a && o.previousPanelSection) {
    if (o.previousPanelSection.sectionRoot) {
      o.previousPanelSection.sectionRoot.style = "";
    }
  }
  o.panelId = e;
  o.panelDiv = t;
  var s = panelLayout[e];
  var r = panelLayout[e + "-collapsed"];
  if (s || r) {
    o.restoreCustomSize = () => {
      try {
        if (s) {
          o.sectionRoot.style.flexBasis = parseInt(s) + "px";
          o.sectionRoot.style.flexGrow = "0";
        }
        if (r) {
          o.sectionRoot.classList.add("sectionHidden");
          o.classList.add("sectionHeaderCollapsed");
        }
      } catch (e) {}
    };
  }
  if (!t.isToolWindow) {
    var l = createDOMElement(o, "div", "paneResizerVertical");
    l.isResizer = true;
    o.resizerDiv = l;
    l.onclick = (e) => {
      e.stopPropagation();
      e.preventDefault();
      return false;
    };
    l.ondblclick = (e) => {
      o.previousPanelSection.sectionRoot.style = "";
      o.sectionRoot.style = "";
      savePanelsConfiguration();
      e.stopPropagation();
      e.preventDefault();
      return false;
    };
    l.onmousedown = (e) => {
      if (e.button === 0) {
        var i = o.previousPanelSection.sectionRoot.clientHeight;
        var n = o.sectionRoot.clientHeight;
        var a = (t) => {
          var a = i + (t.pageY - e.pageY);
          var s = n - (t.pageY - e.pageY);
          if (a < 0 || s < 0) return;
          o.previousPanelSection.sectionRoot.style.flexBasis = a + "px";
          o.previousPanelSection.sectionRoot.style.flexGrow = "0";
          o.previousPanelSection.sectionRoot.style.flexShrink = "0";
          o.sectionRoot.style.flexBasis = s + "px";
          o.sectionRoot.style.flexGrow = "0";
          o.sectionRoot.style.flexShrink = "0";
        };
        var s = (r) => {
          document.removeEventListener("mousemove", a);
          document.removeEventListener("mouseup", s);
          var l = i + (r.pageY - e.pageY);
          var d = n - (r.pageY - e.pageY);
          if (l < 0 || d < 0) return;
          o.previousPanelSection.sectionRoot.style.flexBasis = l + "px";
          o.previousPanelSection.sectionRoot.style.flexGrow = "0";
          o.previousPanelSection.sectionRoot.style.flexShrink = "0";
          o.sectionRoot.style.flexBasis = d + "px";
          o.sectionRoot.style.flexGrow = "0";
          o.sectionRoot.style.flexShrink = "0";
          t.layoutChanged(t);
        };
        document.addEventListener("mousemove", a);
        document.addEventListener("mouseup", s);
        e.stopPropagation();
        e.preventDefault();
        return false;
      }
    };
  }
  if (!t.isToolWindow) {
    makeDraggablePanelHeader(o);
  }
  return o;
}
function addHorizontalPanelSection(e, t, i, n, a) {
  t.countOfSections++;
  var o = createDOMElement(
    t,
    "div",
    "centerInnerPanelColumn " + (n ? "isPsuedo" : "")
  );
  if (!n) o.isRealPanelSection = true;
  o.isPanelSection = true;
  if (a) t.insertBefore(o, a);
  var s = createDOMElement(o, "div", i);
  s.isPanelSection = true;
  o.panelId = e;
  o.innerDiv = s;
  s.panelId = e;
  s.panelDiv = t;
  updateInterPanelLinks(t);
  var r = panelLayout[e];
  var l = panelLayout[e + "-collapsed"];
  if (r || l) {
    s.restoreCustomSize = () => {
      try {
        if (r) {
          o.style.minWidth = parseInt(r) + "px";
          o.style.maxWidth = parseInt(r) + "px";
          o.style.flexGrow = "0";
        }
        if (l) {
        }
      } catch (e) {}
    };
  }
  if (t.countOfSections > 1) {
    var d = createDOMElement(o, "div", "paneResizerHorizontal");
    d.isResizer = true;
    s.resizerDiv = d;
    d.onclick = (e) => {
      e.stopPropagation();
      return false;
    };
    d.ondblclick = (e) => {
      s.previousPanelSection.parentNode.style = "";
      o.style = "";
      savePanelsConfiguration();
      e.stopPropagation();
      return false;
    };
    d.onmousedown = (e) => {
      if (e.button === 0) {
        var i = s.previousPanelSection.parentNode.offsetWidth;
        var n = o.offsetWidth;
        var a = (t) => {
          var a = i + (t.pageX - e.pageX);
          var r = n - (t.pageX - e.pageX);
          if (a < 0 || r < 0) return;
          s.previousPanelSection.parentNode.style.minWidth = a + "px";
          s.previousPanelSection.parentNode.style.maxWidth = a + "px";
          o.style.minWidth = r + "px";
          o.style.maxWidth = r + "px";
        };
        var r = (l) => {
          document.removeEventListener("mousemove", a);
          document.removeEventListener("mouseup", r);
          var d = i + (l.pageX - e.pageX);
          var c = n - (l.pageX - e.pageX);
          if (d < 0 || c < 0) return;
          s.previousPanelSection.parentNode.style.minWidth = d + "px";
          s.previousPanelSection.parentNode.style.maxWidth = d + "px";
          o.style.minWidth = c + "px";
          o.style.maxWidth = c + "px";
          t.layoutChanged(t);
        };
        document.addEventListener("mousemove", a);
        document.addEventListener("mouseup", r);
        e.stopPropagation();
        e.preventDefault();
        return false;
      }
    };
  }
  makeDraggablePanelHeader(s);
  return s;
}
function toggleSectionExpansion(e, t, i) {
  if (e.classList.contains("sectionHidden")) {
    e.classList.remove("sectionHidden");
    t.classList.remove("sectionHeaderCollapsed");
    savePanelsConfiguration();
  } else {
    e.classList.add("sectionHidden");
    t.classList.add("sectionHeaderCollapsed");
    savePanelsConfiguration();
  }
}
